package net.googlecode.vasetskiy.task3;

import java.math.BigDecimal;

/**
 * Created by IntelliJ IDEA.
 * User: Vasetskiy Vlad
 * Date: 29.03.11
 * Time: 13:53
 * To change this template use File | Settings | File Templates.
 */
public class SalaryCalculator {
    private BigDecimal mngTax;
    private BigDecimal empTax;
    private BigDecimal bossTax;
    /**
     * Constructor, creates salary calculator with default taxes.
     */
    public SalaryCalculator() {
        this.setDirectTax(new BigDecimal(500));
        this.setMngTax(new BigDecimal(250));
        this.setEmpTax(new BigDecimal(125));
    }
    /**
     * Constructor that creates salary calculator with entered taxes.
     *
     * @param bossTax Boss tax
     * @param mngTax  Manager tax
     * @param empTax  Employee tax
     */
    public SalaryCalculator(final BigDecimal bossTax, final BigDecimal mngTax, final BigDecimal empTax) {
        this.setDirectTax(bossTax);
        this.setMngTax(mngTax);
        this.setEmpTax(empTax);
    }
    /**
     * Sets Employees tax
     *
     * @param empTax employees tax
     */
    public void setEmpTax(final BigDecimal empTax) {
        this.empTax = empTax;
    }
    /**
     * Sets managers tax
     *
     * @param mngTax managers tax
     */
    public void setMngTax(final BigDecimal mngTax) {
        this.mngTax = mngTax;
    }
    /**
     * Sets Director tax
     *
     * @param bossTax Director tax
     */
    public void setDirectTax(final BigDecimal bossTax) {
        this.bossTax = bossTax;
    }
    /**
     * Counts Manager salary.
     *
     * @param man Manager.
     * @return manager salary.
     */
    private BigDecimal salaryManager(final Manager man) {
        BigDecimal salary = new BigDecimal(0);
        if (man.getPerHour()) {
            salary = new BigDecimal(170).multiply(man.getRate());
        } else {
            salary = man.getRate();
            }
          if (man.getBonus()) {
            salary = salary.add(man.getBonusAmount());
          }
        salary = salary.subtract(mngTax);
        return salary;
    }
    /**
     * Counts Employee salary.
     *
     * @param emp Employee
     * @return Employee salary
     */
    private BigDecimal salaryEmployee(final Employee emp) {
        BigDecimal salary = new BigDecimal(0);
        if (emp.getPerHour()) {
            //170 hours in month
            salary = new BigDecimal(170).multiply(emp.getRate());
        } else {
            //salary = rate * experience
            salary = emp.getRate().multiply(new BigDecimal(emp.getExperience()));
        }
        if (emp.getBonus()) {
            salary = salary.add(emp.getBonusAmount());
        }
        salary = salary.subtract(empTax);
        return salary;
    }
    /**
     * Counts Director salary.
     *
     * @param bos Director
     * @return Director salary
     */
    private BigDecimal salaryBoss(Director bos) {
        BigDecimal salary = new BigDecimal(170).multiply(bos.getRate());
        salary = salary.add(bos.getBonusAmount());
        salary = salary.subtract(bossTax);
        return salary;
    }
    /**
     * Prints personal information about person: Profession, name, age, salary.
     *
     * @param person Person
     */
    private void printPersonInform(PersonInform person, BigDecimal salary) {
      System.out.println(person.getClass().getSimpleName() + " >> " + person.getName() + ", age: " + person.getAge() + ", salary: $" + salary);
    }
    /**
     * Checks who is the person and counts person's salary.
     *
     * @param person
     */
    public void calcSalary(Object person) {
        BigDecimal salary = new BigDecimal(0);
        if (person instanceof Manager) {
            printPersonInform((Manager) person, salaryManager((Manager) person));
        } else if (person instanceof Employee) {
            printPersonInform((Employee) person, salaryEmployee((Employee) person));
        } else {
            if (person instanceof Director) {
                printPersonInform((Director) person, salaryBoss((Director) person));
            }
        }


    }
}
